﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMA.GENTEv1.Dados;

namespace SMA.GENTEv1
{
    public class WorkflowNivel
    {
        #region Variaveis Membro
        private int _idWfNivel;
        private string _descricao;
        private GENTEEntities _context;
        #endregion

        #region Parametros
        public int IdWfNivel
        {
            get { return _idWfNivel; }
            set { _idWfNivel = value; }
        }
        public string Descricao
        {
            get { return _descricao; }
            set { _descricao = value; }
        }
        #endregion

        #region Construtores
        public WorkflowNivel()
        {
            try
            {
                _context = new GENTEEntities();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public WorkflowNivel(int idWfNivel)
        {
            try
            {
                _context = new GENTEEntities();
                Carregar(idWfNivel);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Metodos Privados
        private void Carregar(int idWfNivel)
        {
            try
            {
                var consulta = from wn in _context.tab_nivel_workflow
                               where wn.id_nivel_workflow == idWfNivel
                               select wn;

                var listConsulta = consulta.ToList();

                foreach (var list in listConsulta)
                {
                    this._idWfNivel = list.id_nivel_workflow;
                    this._descricao = list.descricao;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Metodo Publicos
        public List<WorkflowNivel> SelectAll()
        {
            try
            {
                List<WorkflowNivel> listWfNivel = new List<WorkflowNivel>();

                var consulta = from wn in _context.tab_nivel_workflow
                               select wn;

                var listConsulta = consulta.ToList();

                foreach (var list in listConsulta)
                {
                    WorkflowNivel wfNivel = new WorkflowNivel();
                    wfNivel.IdWfNivel = list.id_nivel_workflow;
                    wfNivel.Descricao = list.descricao;

                    listWfNivel.Add(wfNivel);
                }

                return listWfNivel;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List<WorkflowNivel> SelectAlerta()
        {
            try
            {
                List<WorkflowNivel> listWfNivel = new List<WorkflowNivel>();

                var consulta = from wn in _context.tab_nivel_workflow
                               where (wn.id_nivel_workflow == 10 //10	Alerta1
                                    || wn.id_nivel_workflow == 11 //11	Alerta2
                                    || wn.id_nivel_workflow == 14 //14	Alerta3
                                    || wn.id_nivel_workflow == 15) //15	Alerta4
                               select wn;

                var listConsulta = consulta.ToList();

                foreach (var list in listConsulta)
                {
                    WorkflowNivel wfNivel = new WorkflowNivel();
                    wfNivel.IdWfNivel = list.id_nivel_workflow;
                    wfNivel.Descricao = list.descricao;

                    listWfNivel.Add(wfNivel);
                }

                return listWfNivel;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List<WorkflowNivel> SelectAviso()
        {
            try
            {
                List<WorkflowNivel> listWfNivel = new List<WorkflowNivel>();

                var consulta = from wn in _context.tab_nivel_workflow
                               where (wn.id_nivel_workflow == 12 //12	Aviso1
                                        || wn.id_nivel_workflow == 13 //13	Aviso2
                                        || wn.id_nivel_workflow == 16 //16	Aviso3
                                        || wn.id_nivel_workflow == 17) //17	Aviso4
                               select wn;

                var listConsulta = consulta.ToList();

                foreach (var list in listConsulta)
                {
                    WorkflowNivel wfNivel = new WorkflowNivel();
                    wfNivel.IdWfNivel = list.id_nivel_workflow;
                    wfNivel.Descricao = list.descricao;

                    listWfNivel.Add(wfNivel);
                }

                return listWfNivel;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}
